package cm.sms.mapper;

import cm.mapper.BaseMapperX;
import cm.sms.DO.SmsCodeDO;
import cm.sms.DO.SmsTemplateDO;
import cm.sms.dto.SmsSendDTO;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.Date;

/**
 * @author: yxh
 * @Description: 模板
 * @Date: Created in 2022/9/20 13:36
 * @Modified By:
 */
@Mapper
public interface SmsTemplateMapper extends BaseMapper<SmsTemplateDO> {

    default SmsTemplateDO selectSmsTemplate(String code) {
        QueryWrapper<SmsTemplateDO> queryWrapper = new QueryWrapper();
        queryWrapper.lambda()
                .eq(SmsTemplateDO::getCode, code)
                .orderByDesc(SmsTemplateDO::getId)
                .last("limit 1");
        return this.selectOne(queryWrapper);
    }


    @Select("SELECT COUNT(*) FROM system_sms_template WHERE update_time > #{maxUpdateTime}")
    Long selectCountByUpdateTimeGt(Date maxUpdateTime);

}
